<template>
	<view class="container">
	
		<view class="bg-top bg-blue">
			<view class="top-box shadow">
					
				<view class="cu-list menu">
	
					<u-form :model="model" ref="uForm" label-width="80">
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="用户昵称" prop="nickName">
								<u-input v-model="model.nickName" placeholder="请输入用户昵称" />
							</u-form-item>	
						</view>
		
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="归属部门" prop="deptId">
								<u-input v-model="model.deptId" placeholder="请选择归属部门" />
							</u-form-item>
						</view>
		
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="手机号码" prop="phonenumber">
								<u-input v-model="model.phonenumber" placeholder="请输入手机号码" />
							</u-form-item>	
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="邮箱" prop="email">
								<u-input v-model="model.email" placeholder="请输入邮箱" />
							</u-form-item>
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item v-if="model.userId == undefined" label="用户名称" prop="userName">
								<u-input v-model="model.userName" placeholder="请输入用户名称" />
							</u-form-item>
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item v-if="model.userId == undefined" label="用户密码" prop="password">
								<u-input v-model="model.password" placeholder="请输入用户密码" type="password" />
							</u-form-item>
						</view>					
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="用户性别" prop="sex">
								<dictSelect v-model="model.sex" placeholder="请选择性别" dictType="sys_user_sex"></dictSelect>
							</u-form-item>	
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="状态" prop="status">
								<dictRadio v-model="model.status" placeholder="请选择状态" dictType="sys_normal_disable"></dictRadio>
							</u-form-item>	
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="岗位" prop="postIds">
								<u-input v-model="model.postIds" placeholder="请选择岗位" disabled />
							</u-form-item>	
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="角色" prop="roleIds">
								<u-input v-model="model.roleIds" placeholder="请选择角色" disabled />
							</u-form-item>	
						</view>
						
						<view class="cu-item" style="padding: 0;">
							<u-form-item label="备注" prop="remark">
								<u-textarea v-model="model.remark" placeholder="请输入备注" />
							</u-form-item>	
						</view>
						
					</u-form>
							
				</view>
	
			</view>
			
			<view style="height: 150rpx; width: 1rpx;"></view>
			
			<view class="cu-bar bg-white tabbar border shop solid-top" style="position: fixed; bottom: 0;width: 100%; z-index: 9999;">
				<view class="btn-group">
					<button @click="submit" style="width: 80%;" class="cu-btn bg-gradual-blue round shadow-blur">{{btnText}}</button>
				</view>
			</view>	
			
		</view>
	</view>
</template>
<script>
import { editMixin } from "@/mixins/edit"
import dictRadio from "@/components/dict-radio"
import dictSelect from "@/components/dict-select"		

export default {
	mixins: [ editMixin ],
	components: { dictRadio, dictSelect },
	data() {
		return {
			// 表单校验
			rules: {
			  userName: [
			    { required: true, message: "用户名称不能为空", trigger: "blur" },
			    { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
			  ],
			  nickName: [
			    { required: true, message: "用户昵称不能为空", trigger: "blur" }
			  ],
			  password: [
			    { required: true, message: "用户密码不能为空", trigger: "blur" },
			    { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }
			  ],
			  email: [
			    {
			      type: "email",
			      message: "请输入正确的邮箱地址",
			      trigger: ["blur", "change"]
			    }
			  ],
			  phonenumber: [
			    {
			      pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
			      message: "请输入正确的手机号码",
			      trigger: "blur"
			    }
			  ]
			}      
		};
	},
	onLoad(options) {

	},
	methods: {
		//调用save接口
		callSave(temp) {
		    let _this = this;
		    return new Promise(function(resolve, reject) {
				_this.$u.api.user.save(temp).then((res) => {
					resolve(res);
				}).catch((error) => {
					reject(error)
				});			
			});  
		},
		//调用findById接口
		callFindById(id) {
		    let _this = this;
		    return new Promise(function(resolve, reject) {
				_this.$u.api.user.findById(id).then((res) => {											
					resolve(res);
				}).catch((error) => {
					reject(error)
				});				
			});  
		}
	}
};

</script>
<style lang="scss">
	@import '@/static/scss/edit.scss';
</style>
